package cn.wolfcode.rbac.util;

import cn.wolfcode.rbac.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public class UserContext {
    public static final String EMPLOYEE_IN_SESSION= "EMPLOYEE_IN_SESSION";
    public static final String EXPRESSION_IN_SESSION= "EXPRESSION_IN_SESSION";

    public static HttpSession getSession(){
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        return servletRequestAttributes.getRequest().getSession();
    }

    public static void setCurrent(Employee employee){
        getSession().setAttribute(EMPLOYEE_IN_SESSION,employee);
    }

    public static Employee getCurrent(){
        return (Employee) getSession().getAttribute(EMPLOYEE_IN_SESSION);
    }

    public static void setExpressions(List<String> expreesions){
        getSession().setAttribute(EXPRESSION_IN_SESSION,expreesions);
    }

    public static List<String> getExpressions(){
        return (List<String>) getSession().getAttribute(EXPRESSION_IN_SESSION);
    }
}
